package cn.sdut.training.web.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

import cn.sdut.training.domain.User;
import cn.sdut.training.service.UserService;

public class LoginAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 1836845503985540865L;
	private Map<String, Object> session;
	//用户输入的用户名和密码
	private String userName;
	private String password;
	
	@Resource
	private UserService userService;
	
	//-------------------------------------------------------
	/**
	 * 处理登录请求
	 */
	public String login(){
		User user = userService.getUserByUsernameAndPassword(userName,password);
		if (user == null) {
			return LOGIN;
		}else{
			session.put("user", user);
		}
		return SUCCESS;
	}
	
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	//-------------------------------------------------
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
